package com.medical.sjq.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class MedicaljigouController {
    @Autowired
    private MedicaljigouService medicaljigouService;


    @RequestMapping("/getMedicaljigouList")
    public String getAreaList(Integer currentPage, Integer limit, HttpServletRequest request, Model model) {
        String medicaljigouName = request.getParameter("context");
        currentPage = currentPage != null ? currentPage : 1;
        limit = limit != null ? limit : 10;

        PageInfo<TbIMedicaljigou> pageInfo = MedicaljigouService.getAllIllness(MedicaljigouName, currentPage, limit);

        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("context", MedicaljigouName);

        return "/Medicaljigou/Medicaljigou_list";
    }

    @RequestMapping("/openAdd")
    public String openAdd(Model model) {
        return "/Medicaljigou/Medicaljigou_add";
    }

    @RequestMapping("/openEdit")
    public String openEidt(Integer id, Model model) {
        Tbmedicaljigou illness = medicaljigouService.getmedicaljigouById(id);

        model.addAttribute("Medicaljigou", medicaljigou);
        return "/medicaljigou/medicaljigou_edit";
    }

    @RequestMapping("/add")
    public String add(TbMedicaljigou medicaljigou, HttpServletRequest request, Model model) {
        medicaljigouService.add(Medicaljigou);
        return getMedicaljigouList(1, 10, request, model);
    }

    @RequestMapping("/edit")
    public String edit(TbMedicaljigou medicaljigou, HttpServletRequest request, Model model) {
        medicaljigouService.edit(medicaljigou);
        return getAreaList(1, 10, request, model);
    }

    @RequestMapping("/delete")
    public String delete(Integer id, HttpServletRequest request, Model model) {
        medicaljigouService.delete(id);
        return getMedicaljigouList(1, 10, request, model);
    }

    @ResponseBody
    @RequestMapping("getMedicaljigouTreeList")
    public Object getAreaTreeList() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("MedicaljigouList", medicaljigouService.getMedicaljigouTree(""));
        return map;
    }

}
}
